<style lang="less">
@import "@/styles/table-common.less";
.btn-box{
  // padding: 10px 12px 10px 0;
  height: 32px;
  display: flex;
  align-items: center;
  span{
    margin-left: 15px;
  }
}
.detail-modal{
  .form{
    div{
      display: flex;
      margin-bottom: 10px;
      span{
        width: 130px;
      }
      input{
        flex: 1;
        border: 1px solid #e8eaec;
        outline: none;
        text-indent: 16px;
        color: #515a6e;
      }
    }
  }
  .refund-num{
    margin-top: 15px;
  }
}

</style> 
<template>
  <div class="search">
    <Card>
      <!-- <Row class="operation">
        <Button @click="add" type="primary" icon="md-add">添加</Button>
      </Row> -->
      <Form ref="searchForm" :model="searchForm" inline :label-width="100">
        <Row v-show="openSearch" @keydown.enter.native="handleSearch">
          
          <FormItem label="订单编号">
            <Input
              type="text"
              v-model="searchForm.orderNo"
              clearable
              placeholder="请输入订单编号"
              style="width: 200px"
            />
          </FormItem>
          <FormItem label="订单发起人">
            <Input
              type="text"
              v-model="searchForm.realName"
              clearable
              placeholder="请输入订单发起人"
              style="width: 200px"
            />
          </FormItem>
          <FormItem label="发起人手机号">
            <Input
              type="text"
              v-model="searchForm.uMobile"
              clearable
              placeholder="请输入发起人手机号"
              style="width: 200px"
            />
          </FormItem>
          <!-- <FormItem label="订单状态">
            <Select v-model="searchForm.status" transfer placeholder="请选择" style="width: 200px">
              <Option v-for="item in orderTypeList" :key="item.id" :value="item.id">{{item.title}}</Option>
            </Select>
          </FormItem> -->
          <FormItem label="订单发起时间">
            <DatePicker
              :options="options"
              v-model="selectDate"
              type="daterange"
              format="yyyy-MM-dd"
              clearable
              @on-change="selectDateRange"
              placeholder="选择起始时间"
              style="width: 200px"
            ></DatePicker>
          </FormItem>
          <!-- <FormItem label="选择角色状态">
            <Select v-model="searchForm.parkRoleId" transfer placeholder="请选择" style="width: 200px">
              <Option v-for="item in idenList" :key="item.id" :value="item.id">{{item.title}}</Option>
            </Select>
          </FormItem> -->
         
          <FormItem style="margin-left: -35px" class="br">
            <Button @click="handleSearch" type="primary" icon="ios-search"
              >搜索</Button
            >
            <Button @click="handleReset">重置</Button>
          </FormItem>
        </Row>
      </Form>
      
      <Table
        :loading="loading"
        border
        :columns="columns"
        :data="data"
        sortable="custom"
        ref="table"
      >
        <!-- <template slot-scope="{ row }" slot="print">{{ row.print.serialNo }}</template> -->
      </Table>
      <Row type="flex" justify="end" class="page">
        <Page
          :current="searchForm.pageNumber"
          :total="total"
          :page-size="searchForm.pageSize"
          @on-change="changePage"
          @on-page-size-change="changePageSize"
          :page-size-opts="[10, 20, 50]"
          size="small"
          show-total
          show-elevator
          show-sizer
        ></Page>
      </Row>
      
    </Card>
    <addEdit
      :data="form"
      :type="showType"
      v-model="showUser"
      @on-submit="getDataList"
    />
    <Modal
        v-model="modal"
        title="详情"
        @on-ok="ok"
        @on-cancel="cancel">
        <div class="detail-modal">
          <div class="form">
            <div><span>订单编号</span><input type="text" readonly :value="detailData.orderNo"></div>
            <div><span>发起人姓名</span><input type="text" readonly :value="detailData.realName"></div>
            <div><span>发起时间</span><input type="text" readonly :value="detailData.createTime"></div>
            <div><span>取消原因</span><input type="text" readonly :value="detailData.refundReasonWapExplain"></div>
          </div>
        </div>
        <div slot="footer">
        </div>
    </Modal>
  </div>
</template>

<script>
import {
  scRuleGuideUpdStatu,

  getScOrderByCondition
} from "@/api/index";

import { shortcuts } from "@/libs/shortcuts";

import addEdit from "./addEdit.vue";
export default {
  name: "user-manage",
  components: {
    addEdit,
  },
  data() {
    return {
      message: "",
      height: 510,
      showUser: false,
      showType: "0",
      loading: true,
      selectDate: '',
      openSearch: true,
      idenList: [], //角色状态
      options: {
        shortcuts: shortcuts,
      },
      orderTypeList: [
        {id: '0', title: '已取消'},
        {id: '1', title: '已完成'},
      ],
      searchForm: {
        orderType: 3,
        pageNumber: 1,
        pageSize: '10',
        sort: "createTime",
        order: "desc",
        // companyName: '会议',
        // startDate: '2021-04-01 11:00:00',
        // endDate: '2021-05-01 11:00:00',
        // uid: '1386481574513610752'
      },
      columns: [
        {
          title: "订单编号",
          key: "orderNo",
          minWidth: 220,
          align: "center",
          fixed: "left"
        },
        {
          title: "会议室名称",
          key: "parkRoleType",
          width: 180,
          align: "center",
          render: (h, params) => {
            return h("span", params.row.meetRoom.title)
          },
        },
        {
          title: "设备号",
          key: "icon",
          width: 180,
          align: "center",
          render: (h, params) => {
            return h("span", params.row.meetRoom.equipSerial)
          },
        },
        {
          title: "企业名称",
          key: "ucompanyName",
          width: 220,
          align: "center",
        },
        {
          title: "订单发起人",
          key: "realName",
          width: 220,
          align: "center",
        },
        {
          title: "发起人手机号",
          key: "userPhone",
          width: 180,
          align: "center",
        },
        {
          title: "订单发起时间",
          key: "createTime",
          width: 220,
          align: "center",
        },
        {
          title: "参会邀请码",
          key: "verifyCode",
          width: 220,
          align: "center",
        },
        {
          title: "会议室预定时间",
          key: "orderDetails",
          width: 220,
          align: "center",
          render: (h, params) => {
            return h("span", params.row.orderDetails[0].startDate + '~' + params.row.orderDetails[0].endDate)
          },
        },
        {
          title: "单价",
          key: "price",
          width: 80,
          align: "center",
          render: (h, params) => {
            return h("span", params.row.meetRoom.meetRoomSet.price)
          },
        },
        {
          title: "总价",
          key: "totalPrice",
          width: 80,
          align: "center",
        },
        {
          title: "积分类型",
          key: "useIntegralType",
          width: 220,
          align: "center",
          render: (h, params) => {
            let txt = this.publicFun.integralType(params.row.useIntegralType);
            return h('span',[
              txt
            ])
          }
        },
          {
          title: "使用积分",
          key: "useIntegral",
          width: 120,
          align: "center",
          render: (h, params) => {
            let txt =params.row.useIntegral;
            return h('span',[
              txt
            ])
          }
        },
       
        {
          title: "数量",
          key: "totalNum",
          width: 80,
          align: "center",
        },
        {
          title: "最后支付金额",
          key: "payPrice",
          width: 180,
          align: "center",
        },
        {
          title: "支付类型",
          key: "paySubType",
          width: 100,
          align: "center",
          render: (h, params) => {
            let txt = this.publicFun.paySubType(params.row.paySubType);
            return h('span',[
              txt
            ])
          }
        },
        {
          title: "状态",
          key: "status",
          width: 100,
          align: "center",
          render: (h, params) => {
            let txt = this.publicFun.orderStatus(params.row.status);
            return h('span',[
              txt
            ])
          }
        },
       
        {
          title: "操作",
          key: "createTime",
          width: 100,
          fixed: "right",
          render: (h, params) => {
            let enableOrDisable = "";
            enableOrDisable = h(
              "a",
              {
                on: {
                  click: () => {
                    this.modal = true
                    this.detailData = params.row
                  }
                }
              },
              "详情"
            )
            return h("div", [
              enableOrDisable,
            ]);
          },
        },
        
      ],
      modal: false,
      columns1: [
          {
            title: '打印机编号',
            key: 'serialNo',
            align: 'center'
          },
        {
            title: '打印名称',
            key: 'title',
            align: 'center'
          },
          {
            title: '打印页数',
            key: 'nums',
            align: 'center'
          },
          {
            title: '*元，每页',
            key: 'price',
            align: 'center'
          }
      ],
      data: [],
      detailData: []
    };
  },
  methods: {
    init() {
      this.getDataList();
      // this.getScOrderByConditionData()
    },
   changeSort(e) {
      this.searchForm.sort = e.key;
      this.searchForm.order = e.order;
      if (e.order == "normal") {
        this.searchForm.order = "";
      }
      this.getDataList();
    },
    getDataList() {
      // 多条件搜索用户列表
      this.loading = true;
      getScOrderByCondition(this.searchForm).then(res => {
        this.loading = false
        console.log(res.message)
        if (res.success) {
          this.data = res.result.content;
          this.total = res.result.totalElements;
          if (this.data.length == 0 && this.searchForm.pageNumber > 1) {
            this.searchForm.pageNumber -= 1;
            this.getDataList();
          }
        }
      })
    },
    getScOrderByConditionData() {
      getScOrderByCondition(this.searchForm).then(res => {
        if (res.success) {
          this.data = res.result.content;
          this.total = res.result.totalElements;
          if (this.data.length == 0 && this.searchForm.pageNumber > 1) {
            this.searchForm.pageNumber -= 1;
            this.getDataList();
          }
        }
      })
    },
    add() {
      this.showType = "2";
      this.showUser = true;
    },
    changePage(v) {
      this.searchForm.pageNumber = v;
      this.getDataList();
    },
    changePageSize(v) {
      this.searchForm.pageSize = v;
      this.getDataList();
    },
    selectDateRange(v) {
      if (v) {
        this.searchForm.startDate = v[0];
        this.searchForm.endDate = v[1];
      }
    },
    handleSearch() {
      this.searchForm.pageNumber = 1;
      this.searchForm.pageSize = 10;
      console.log(this.searchForm)
      // return
      this.getDataList();
    },
    handleReset() {
      this.selectDate = ''
      this.searchForm.startDate = ''
      this.searchForm.endDate = ''
      this.searchForm.orderNo = ''
      this.searchForm.realName = ''
      this.searchForm.mobile = ''
      this.searchForm.endDate = ''
      this.searchForm.pageNumber = 1;
      this.searchForm.pageSize = 10;
      // 重新加载数据
      this.getDataList();
    },
    enable(v) {
      this.$Modal.confirm({
        title: "确认启用",
        content: "您确认要启用用户 " + v.title + " ?",
        loading: true,
        onOk: () => {
          enableUser(v.id).then((res) => {
            this.$Modal.remove();
            if (res.success) {
              this.$Message.success("操作成功");
              this.getDataList();
            }
          });
        },
      });
    },
    chageable(v, status) {
      let statusTxt = status == 0 ? '启用' : '禁用'
      this.$Modal.confirm({
        title: `确认${statusTxt}`,
        content: `您确认要${statusTxt}` + v.title + " ?",
        loading: true,
        onOk: () => {
          scRuleGuideUpdStatu({id:v.id, status}).then((res) => {
            this.$Modal.remove();
            if (res.success) {
              this.$Message.success("操作成功");
              this.getDataList();
            }
          });
        },
      });
    },
    cancel() {

    },
    ok() {

    }
  },
  created() {
  },
  mounted() {
    // 计算高度
    this.height = Number(document.documentElement.clientHeight - 230);
    this.init();
  },
};
</script>